﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace UI.NetworkDiagram
{
    public struct Vector
    {
        Point _point;

        public Vector(double x, double y)
        {
            _point = new Point(x, y);
        }

        public double Length
        {
            get { return (Math.Sqrt(Math.Pow(_point.X, 2.0) + Math.Pow(_point.Y, 2.0))); }
        }

        public void Normalize()
        {
            if (Length == 0)
                throw new System.InvalidOperationException("Vector Length is zero, can not normalize");

            double l = Length;
            _point.X /= l;
            _point.Y /= l;
        }

        public double X
        {
            get { return _point.X; }
            set { _point.X = value; }
        }

        public double Y
        {
            get { return _point.Y; }
            set { _point.Y = value; }
        }

        public Point ToPoint()
        {
            return new Point(X,Y);
        }

        public static Vector operator -(Vector vector1, Vector vector2)
        {
            return new Vector(vector1.X - vector2.X, vector1.Y - vector2.Y);
        }


        public static Vector operator -(Vector vector)
        {
            return new Vector(-vector.X, -vector.Y);
        }

        
        public static Vector operator *(double scalar, Vector vector)
        {
            return new Vector(vector.X * scalar, vector.Y * scalar);
        }

        
        public static Vector operator *(Vector vector, double scalar)
        {
            return new Vector(vector.X * scalar, vector.Y * scalar);
        }

        
        public static double operator *(Vector vector1, Vector vector2)
        {
            return (vector1.X * vector2.X) + (vector1.Y * vector2.Y);
        }

        
        public static Vector operator +(Vector vector1, Vector vector2)
        {
            return (new Vector(vector2.X + vector1.X, vector2.Y + vector1.Y));
        }

        
        public static Point operator +(Point point, Vector vector)
        {
            return new Point(point.X + vector.X, point.Y + vector.Y);
        }

    }
}
